//域名
var mainurl = "/xy/";
//var mainurl = "http://1208f7ff.nat123.cc/xy/";
// var mainurl = "http://127.0.0.1:8080/xy/";
//var mainurl = "http://127.0.0.1/xy/";
//var mainurl = "http://123.56.223.158/xy/";
//是否跨域

var isCrossDomain = false;

function checkData(data) {
    if (data.code != 0){
        errorInfo(data.msg);
        if(data.code==-1){
            window.location.href=mainurl+'hbwlxy/admin/login.html';
        }
        return false;
    }
    return true;
}

function errorInfo(info) {
    layer.msg(info, {icon: 2,time: 1000});
}

function warnInfo(info) {
    layer.msg(info, {icon: 0,time: 1000});
}

function successInfo(info) {
    layer.msg(info, {icon: 1,time: 1000});
}

(function getUrlParam($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
})(jQuery);


function setImgNoNull() {
    var img = $("input[type='hidden'][name='img']");
    if(img.attr("value")==null || img.attr("value")=='') {
        img.attr("value","/");
    }
}


function toDate(str) {
    var d = new Date(Number(str));
    var ss = ""+d.getFullYear();
    if((d.getMonth()+1)>9) {
        ss += ("-"+(d.getMonth()+1));
    } else {
        ss += ("-0"+(d.getMonth()+1));
    }
    if(d.getDate()>9){
        ss += ("-"+d.getDate());
    } else {
        ss += ("-0"+d.getDate());
    }
    return ss;
}

function setDataById(data) {
    for (var k in data) {
        if(k=="img") {
            $("#img").attr("src", mainurl+data[k]);
            continue;
        }
        if(k=="audit") {
            var str = "";
            switch (data[k]){
                case -1: str="审核通过";break;
                case 0: str="审核中";break;
            }
            $("#audit").text(str);
            continue;
        }
        $("#"+k).text(data[k]);
    }
}


function setDataByName(data) {
    for (var k in data) {

        var obj3 = $("input[name='"+k+"']");
        if(obj3.attr("type")=="radio"){
            $("input[name='"+k+"'][value='"+data[k]+"']").attr("checked", true);
        } else if(obj3.attr("type")=="checkbox") {

        } else {
            obj3.attr("value",data[k]);
        }
        var obj1 = $("textarea[name='"+k+"']");
        if(obj1.length>0) {
            obj1.text(data[k]);
            continue;
        }
        var obj2 = $("select[name='"+k+"'] option[value='"+data[k]+"']");
        if(obj2.length>0) {
            obj2.prop("selected",true);
            continue;
        }

    }
}


//动态生成页码
function xuhao(pageNum,pages) {
    var c=pageNum-1;
    var d=pageNum+1;
    var str="<span>第"+pageNum+"页</span><a href=\"#\" onclick='tiaozhuan("+1+")'>首页</a><a href=\"#\" onclick='tiaozhuan("+c+")'>上一页</a>"
    var a=Math.ceil(pages/5);
    var b=Math.ceil(pageNum/5);
    if (b<a){
        for (var i=5*b-4;i<=5*b;i++){
            str=str+"<a onclick='tiaozhuan("+i+")'>"+i+"</a>";
        }
    } else {
        for (var i=5*b-4;i<=pages;i++){
            str=str+"<a onclick='tiaozhuan("+i+")'>"+i+"</a>";
        }
    }
    str=str+"<a href=\"#\" onclick='tiaozhuan("+d+")'>下一页</a><a href=\"#\" onclick='tiaozhuan("+pages+")'>尾页</a>"
    $("#xuhao").append(str);
}
